﻿using System.Collections.Generic;
using System.IO;

namespace TdxHq.Invoker
{
    class DllManager
    {
        public static readonly string DllPath = @".\TdxHqApi.dll";
        
        public static readonly DllManager Instance = new DllManager();

        public Dictionary<string,DllInvoker> Invokers { get; }

        private DllManager()
        {
            Invokers = Generate();
        }
        
        private Dictionary<string,DllInvoker> Generate()
        {
            var dllInvokers = new Dictionary<string, DllInvoker>();
            foreach (var ip in Config.IpList)
            {
                for (int i = 0; i < 10; i++)
                {
                    var destFilePath = @".\" + ip.Key + "_" + i + ".dll";
                    if(!File.Exists(destFilePath))
                    {
                        File.Copy(DllPath, destFilePath);
                    }
                    dllInvokers.Add(ip.Key + "_" + i, new DllInvoker(destFilePath));
                }
            }
            
            return dllInvokers;
        }
    }
}